﻿package core.ui.controls
{
    import flash.display.*;

    public class Menu extends Sprite
    {
        private var holder:Sprite;

        public function Menu()
        {
            this.holder = new Sprite();
            this.holder.x = 4;
            this.holder.y = 4;
            addChild(this.holder);
            return;
        }// end function

        public function AddItem(_arg2:Function, _arg2:String, _arg2:Boolean = false, _arg2:String = "", _arg2:Boolean = true) : void
        {
            var _loc_6:* = new MenuItem(_arg2, _arg2, _arg2, _arg2);
            _loc_6.visible = _arg2;
            _loc_6.y = _loc_6.visible ? (Math.round(this.holder.height)) : (Math.round(this.holder.height - _loc_6.height));
            this.holder.addChild(_loc_6);
            this.Redraw();
            return;
        }// end function

        public function ChangeItemVisibility(_arg2:String, _arg2:Boolean) : void
        {
            var _loc_3:DisplayObject = null;
            var _loc_4:int = 0;
            while (_loc_4 < this.holder.numChildren)
            {
                
                _loc_3 = this.holder.getChildAt(_loc_4) as DisplayObject;
                if (_loc_3.name == _arg2)
                {
                    _loc_3.visible = _arg2;
                }
                _loc_4++;
            }
            this.ReorderItems();
            return;
        }// end function

        public function ReorderItems() : void
        {
            var _loc_1:DisplayObject = null;
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            while (_loc_3 < this.holder.numChildren)
            {
                
                _loc_1 = this.holder.getChildAt(_loc_3) as DisplayObject;
                _loc_1.y = _loc_2;
                if (_loc_1.visible)
                {
                    _loc_2 = _loc_2 + _loc_1.height;
                }
                _loc_3++;
            }
            this.Redraw();
            return;
        }// end function

        public function Redraw() : void
        {
            this.graphics.clear();
            var _loc_1:* = 230;
            var _loc_2:* = this.holder.height + 8;
            this.graphics.beginFill(0, 0.9);
            this.graphics.drawRect(0, 0, _loc_1, 1);
            this.graphics.drawRect(0, (_loc_2 - 1), _loc_1, 1);
            this.graphics.drawRect(0, 1, 1, _loc_2 - 2);
            this.graphics.drawRect((_loc_1 - 1), 1, 1, _loc_2 - 2);
            this.graphics.endFill();
            this.graphics.beginFill(4342853, 0.9);
            this.graphics.drawRect(1, 1, _loc_1 - 2, 1);
            this.graphics.drawRect(1, _loc_2 - 2, _loc_1 - 2, 1);
            this.graphics.drawRect(1, 2, 1, _loc_2 - 4);
            this.graphics.drawRect(_loc_1 - 2, 2, 1, _loc_2 - 4);
            this.graphics.endFill();
            this.graphics.beginFill(131847, 0.9);
            this.graphics.drawRect(2, 2, _loc_1 - 4, _loc_2 - 4);
            this.graphics.endFill();
            return;
        }// end function

        public function Clear() : void
        {
            while (this.holder.numChildren > 0)
            {
                
                this.holder.removeChildAt(0);
            }
            this.Redraw();
            return;
        }// end function

        public function AddSeparator() : void
        {
            var _loc_1:* = new MenuSplit();
            _loc_1.y = Math.round(this.holder.height);
            this.holder.addChild(_loc_1);
            this.Redraw();
            return;
        }// end function

    }
}
